package com.savi.myapplication;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;


public class BaseActivity extends AppCompatActivity {

    EFBGlobalData g_App;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setScreenSelfAdapter();
        g_App = (EFBGlobalData) getApplicationContext();


    }

    /**
     * 菜单设置
     */
    public void initSetting(){

        SharedPreferences sp = getSharedPreferences("configSet", Context.MODE_PRIVATE);
        boolean isShowTabTask = sp.getBoolean("isShowTabTask", false);
        boolean isShowTabCard = sp.getBoolean("isShowTabCard", false);
        g_App.isShowTabTask = isShowTabTask;
        g_App.isShowTabCard = isShowTabCard;

//        if (!g_App.isShowTabTask) {
//
//            findViewById(R.id.ll_fly_task).setVisibility(View.GONE);
//        }else {
//            findViewById(R.id.ll_fly_task).setVisibility(View.VISIBLE);
//        }
//        if (!g_App.isShowTabCard){
//            findViewById(R.id.ll_fly_card).setVisibility(View.GONE);
//        }else {
//            findViewById(R.id.ll_fly_card).setVisibility(View.VISIBLE);
//        }
    }
    /**
     * @param keyCode 键盘码
     * @param event   键盘事件
     * @return 是够阻断此事件
     * @brief 键盘点击事件
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)
            return true;
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onRestart() {
        initSetting();
        setScreenSelfAdapter();
        super.onRestart();
    }

    @Override
    protected void onStart() {
        initSetting();
        super.onStart();
    }

    /**
     * @brief 设置屏幕适配器
     */
    private void setScreenSelfAdapter() {

        DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
        if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            displayMetrics.density = displayMetrics.widthPixels / EFBGlobalData.land_widthPixels; // 1920.0f;

        } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            displayMetrics.density = displayMetrics.widthPixels / EFBGlobalData.portrait_widthPixels; // 1200.0f;
        }
        this.getResources().getDisplayMetrics().setTo(displayMetrics);

    }
}